---
layout: "default"
title: "Operator: %="
description: "Swift documentation for the '%=' operator."
root: "/v4.2"
---

<code class="language-swift"> operator %= {
    associativity right
    precedence 
    assignment
}</code>

<h3>Declarations</h3>

<div class="declaration" id="func-pcteq_-inout-int-rhs_-int">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-pcteq_-inout-int-rhs_-int">func %=(<wbr>_:<wbr> inout Int, rhs: Int)</a>
        
<div class="comment collapse" id="comment-func-pcteq_-inout-int-rhs_-int"><div class="p">
    <p>Divides the first value by the second and stores the remainder in the
left-hand-side variable.</p>

<p>The result has the same sign as <code>lhs</code> and is less than <code>rhs.magnitude</code>.</p>

<pre><code class="language-swift">var x = 22
x %= 5
// x == 2

var y = 22
y %= -5
// y == 2

var z = -22
z %= -5
// z == -2</code></pre>

<p><strong>Parameters:</strong>
  <strong>lhs:</strong> The value to divide.
  <strong>rhs:</strong> The value to divide <code>lhs</code> by. <code>rhs</code> must not be zero.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func %=(lhs: inout Int, rhs: Int)</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-pcteq_-inout-int8-rhs_-int8">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-pcteq_-inout-int8-rhs_-int8">func %=(<wbr>_:<wbr> inout Int8, rhs: Int8)</a>
        
<div class="comment collapse" id="comment-func-pcteq_-inout-int8-rhs_-int8"><div class="p">
    <p>Divides the first value by the second and stores the remainder in the
left-hand-side variable.</p>

<p>The result has the same sign as <code>lhs</code> and is less than <code>rhs.magnitude</code>.</p>

<pre><code class="language-swift">var x = 22
x %= 5
// x == 2

var y = 22
y %= -5
// y == 2

var z = -22
z %= -5
// z == -2</code></pre>

<p><strong>Parameters:</strong>
  <strong>lhs:</strong> The value to divide.
  <strong>rhs:</strong> The value to divide <code>lhs</code> by. <code>rhs</code> must not be zero.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func %=(lhs: inout Int8, rhs: Int8)</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-pcteq_-inout-int16-rhs_-int16">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-pcteq_-inout-int16-rhs_-int16">func %=(<wbr>_:<wbr> inout Int16, rhs: Int16)</a>
        
<div class="comment collapse" id="comment-func-pcteq_-inout-int16-rhs_-int16"><div class="p">
    <p>Divides the first value by the second and stores the remainder in the
left-hand-side variable.</p>

<p>The result has the same sign as <code>lhs</code> and is less than <code>rhs.magnitude</code>.</p>

<pre><code class="language-swift">var x = 22
x %= 5
// x == 2

var y = 22
y %= -5
// y == 2

var z = -22
z %= -5
// z == -2</code></pre>

<p><strong>Parameters:</strong>
  <strong>lhs:</strong> The value to divide.
  <strong>rhs:</strong> The value to divide <code>lhs</code> by. <code>rhs</code> must not be zero.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func %=(lhs: inout Int16, rhs: Int16)</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-pcteq_-inout-int32-rhs_-int32">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-pcteq_-inout-int32-rhs_-int32">func %=(<wbr>_:<wbr> inout Int32, rhs: Int32)</a>
        
<div class="comment collapse" id="comment-func-pcteq_-inout-int32-rhs_-int32"><div class="p">
    <p>Divides the first value by the second and stores the remainder in the
left-hand-side variable.</p>

<p>The result has the same sign as <code>lhs</code> and is less than <code>rhs.magnitude</code>.</p>

<pre><code class="language-swift">var x = 22
x %= 5
// x == 2

var y = 22
y %= -5
// y == 2

var z = -22
z %= -5
// z == -2</code></pre>

<p><strong>Parameters:</strong>
  <strong>lhs:</strong> The value to divide.
  <strong>rhs:</strong> The value to divide <code>lhs</code> by. <code>rhs</code> must not be zero.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func %=(lhs: inout Int32, rhs: Int32)</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-pcteq_-inout-int64-rhs_-int64">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-pcteq_-inout-int64-rhs_-int64">func %=(<wbr>_:<wbr> inout Int64, rhs: Int64)</a>
        
<div class="comment collapse" id="comment-func-pcteq_-inout-int64-rhs_-int64"><div class="p">
    <p>Divides the first value by the second and stores the remainder in the
left-hand-side variable.</p>

<p>The result has the same sign as <code>lhs</code> and is less than <code>rhs.magnitude</code>.</p>

<pre><code class="language-swift">var x = 22
x %= 5
// x == 2

var y = 22
y %= -5
// y == 2

var z = -22
z %= -5
// z == -2</code></pre>

<p><strong>Parameters:</strong>
  <strong>lhs:</strong> The value to divide.
  <strong>rhs:</strong> The value to divide <code>lhs</code> by. <code>rhs</code> must not be zero.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func %=(lhs: inout Int64, rhs: Int64)</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-pcteq_-inout-uint-rhs_-uint">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-pcteq_-inout-uint-rhs_-uint">func %=(<wbr>_:<wbr> inout UInt, rhs: UInt)</a>
        
<div class="comment collapse" id="comment-func-pcteq_-inout-uint-rhs_-uint"><div class="p">
    <p>Divides the first value by the second and stores the remainder in the
left-hand-side variable.</p>

<p>The result has the same sign as <code>lhs</code> and is less than <code>rhs.magnitude</code>.</p>

<pre><code class="language-swift">var x = 22
x %= 5
// x == 2

var y = 22
y %= -5
// y == 2

var z = -22
z %= -5
// z == -2</code></pre>

<p><strong>Parameters:</strong>
  <strong>lhs:</strong> The value to divide.
  <strong>rhs:</strong> The value to divide <code>lhs</code> by. <code>rhs</code> must not be zero.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func %=(lhs: inout UInt, rhs: UInt)</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-pcteq_-inout-uint8-rhs_-uint8">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-pcteq_-inout-uint8-rhs_-uint8">func %=(<wbr>_:<wbr> inout UInt8, rhs: UInt8)</a>
        
<div class="comment collapse" id="comment-func-pcteq_-inout-uint8-rhs_-uint8"><div class="p">
    <p>Divides the first value by the second and stores the remainder in the
left-hand-side variable.</p>

<p>The result has the same sign as <code>lhs</code> and is less than <code>rhs.magnitude</code>.</p>

<pre><code class="language-swift">var x = 22
x %= 5
// x == 2

var y = 22
y %= -5
// y == 2

var z = -22
z %= -5
// z == -2</code></pre>

<p><strong>Parameters:</strong>
  <strong>lhs:</strong> The value to divide.
  <strong>rhs:</strong> The value to divide <code>lhs</code> by. <code>rhs</code> must not be zero.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func %=(lhs: inout UInt8, rhs: UInt8)</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-pcteq_-inout-uint16-rhs_-uint16">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-pcteq_-inout-uint16-rhs_-uint16">func %=(<wbr>_:<wbr> inout UInt16, rhs: UInt16)</a>
        
<div class="comment collapse" id="comment-func-pcteq_-inout-uint16-rhs_-uint16"><div class="p">
    <p>Divides the first value by the second and stores the remainder in the
left-hand-side variable.</p>

<p>The result has the same sign as <code>lhs</code> and is less than <code>rhs.magnitude</code>.</p>

<pre><code class="language-swift">var x = 22
x %= 5
// x == 2

var y = 22
y %= -5
// y == 2

var z = -22
z %= -5
// z == -2</code></pre>

<p><strong>Parameters:</strong>
  <strong>lhs:</strong> The value to divide.
  <strong>rhs:</strong> The value to divide <code>lhs</code> by. <code>rhs</code> must not be zero.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func %=(lhs: inout UInt16, rhs: UInt16)</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-pcteq_-inout-uint32-rhs_-uint32">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-pcteq_-inout-uint32-rhs_-uint32">func %=(<wbr>_:<wbr> inout UInt32, rhs: UInt32)</a>
        
<div class="comment collapse" id="comment-func-pcteq_-inout-uint32-rhs_-uint32"><div class="p">
    <p>Divides the first value by the second and stores the remainder in the
left-hand-side variable.</p>

<p>The result has the same sign as <code>lhs</code> and is less than <code>rhs.magnitude</code>.</p>

<pre><code class="language-swift">var x = 22
x %= 5
// x == 2

var y = 22
y %= -5
// y == 2

var z = -22
z %= -5
// z == -2</code></pre>

<p><strong>Parameters:</strong>
  <strong>lhs:</strong> The value to divide.
  <strong>rhs:</strong> The value to divide <code>lhs</code> by. <code>rhs</code> must not be zero.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func %=(lhs: inout UInt32, rhs: UInt32)</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-pcteq_-inout-uint64-rhs_-uint64">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-pcteq_-inout-uint64-rhs_-uint64">func %=(<wbr>_:<wbr> inout UInt64, rhs: UInt64)</a>
        
<div class="comment collapse" id="comment-func-pcteq_-inout-uint64-rhs_-uint64"><div class="p">
    <p>Divides the first value by the second and stores the remainder in the
left-hand-side variable.</p>

<p>The result has the same sign as <code>lhs</code> and is less than <code>rhs.magnitude</code>.</p>

<pre><code class="language-swift">var x = 22
x %= 5
// x == 2

var y = 22
y %= -5
// y == 2

var z = -22
z %= -5
// z == -2</code></pre>

<p><strong>Parameters:</strong>
  <strong>lhs:</strong> The value to divide.
  <strong>rhs:</strong> The value to divide <code>lhs</code> by. <code>rhs</code> must not be zero.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func %=(lhs: inout UInt64, rhs: UInt64)</code>
    
    
</div></div>
</div>
